package com.ly.hotel.spainterface.jxd.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.ly.hotel.R;
import com.ly.hotel.spainterface.jxd.bean.Massage;
import java.util.List;

/**
 * Created by ThinkPad on 2018/3/21.
 */

public class MassageAdapter extends BaseExpandableListAdapter {

    private Context context;
    private List<String> massageCategoryGroup;
    private List<List<Massage>> massageNamesChild;
    private int defaultChildPosition = 0;
    private int defaultGroupPostion = 0;

    public MassageAdapter(Context context, List<String> massageCategoryGroup,List<List<Massage>> massageNamesChild){
        this.context = context;
        this.massageCategoryGroup = massageCategoryGroup;
        this.massageNamesChild = massageNamesChild;
    }

    public void setDefaultChildPosition(int defaultChildPosition) {
        this.defaultChildPosition = defaultChildPosition;
        notifyDataSetChanged();
    }

    public void setDefaultGroupPostion(int defaultGroupPostion) {
        this.defaultGroupPostion = defaultGroupPostion;
    }

    @Override
    public int getGroupCount() {
        return massageCategoryGroup.size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return groupPosition;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return massageNamesChild.get(groupPosition).get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return massageNamesChild.get(groupPosition).size();
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(R.layout.jxd_massage_category_item_group,parent,false);
        TextView massageCategoryName = convertView.findViewById(R.id.massage_category_name);
        massageCategoryName.setText(massageCategoryGroup.get(groupPosition));
        ImageView massageExpandArrow = convertView.findViewById(R.id.massage_expand_arrow);
        if(isExpanded){
            massageExpandArrow.setImageResource(R.mipmap.jxd_massage_open);
        }else{
            massageExpandArrow.setImageResource(R.mipmap.jxd_massage_close);
        }
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(R.layout.jxd_massage_name_item_child,parent,false);
        TextView massageItemName = convertView.findViewById(R.id.massage_item_name);
        massageItemName.setText(massageNamesChild.get(groupPosition).get(childPosition).getMassagename());
        if(defaultGroupPostion == groupPosition && defaultChildPosition == childPosition){
            massageItemName.setTextColor(ContextCompat.getColor(context,R.color.itemName));
        }else{
            massageItemName.setTextColor(ContextCompat.getColor(context,R.color.colorWhite));
        }
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}
